$(function(){

    /*时间先后大小问题*/
    // $("#startDateBirth").blur(function(){
    //     var startDateBirth = $("#startDateBirth").val();
    //     var endDateBirth = $("#endDateBirth").val();
    // })
    // var startDateBirth = $("#startDateBirth").val();
    // var endDateBirth = $("#endDateBirth").val();
    // var startDate = $("#startDate").val();
    // var endDate = $("#endDate").val();

    /**
     * 查询患者信息
     */
    displayLess(1,5)

    /*点击选择*/
    $("#query_all").click(function(){
        displayLess(1,$("#query_page_less").bs_pagination('getOption','rowsPerPage'));
    })
    /*点击清空*/
    $("#query_all_reset").click(function(){
        location.href="findPis.jsp"
    })

    function displayLess(pageNoStr, pageSizeStr) {
        /*调用条件数据*/
        var name = $("#name").val();
        var gender = $("#gender option:selected").val();
        var startDateBirth = $("#startDateBirth").val();
        var endDateBirth = $("#endDateBirth").val();
        var startDate = $("#startDate").val();
        var endDate = $("#endDate").val();

        /*执行ajax*/
        $.ajax({
            url: "../../patientSignsAnemia/findBy",
            data: {
                pageNoStr: pageNoStr,
                pageSizeStr: pageSizeStr,
                name:name,
                gender:gender,
                startDateBirt:startDateBirth,
                endDateBirth:endDateBirth,
                startDate:startDate,
                endDate:endDate,
            },
            type: "post",
            dataType: "json",
            success: function (map) {
                var htmlStr = "";
                var pisList = map.pisList;
                for (var i = 0; i < pisList.length; i++) {
                    htmlStr+="<tr>"
                    htmlStr+="<td>"+pisList[i].patientName+"</td>"
                    var sex = "";
                    if( pisList[i].gender == 1 ){
                        sex = "男";
                    }else if( pisList[i].gender == 2 ){
                        sex = "女";
                    }else{
                        sex = "";
                    }
                    htmlStr+="<td>"+sex+"</td>"
                    var age = "";
                    if( pisList[i].age != null ){
                        age = pisList[i].age;
                    }
                    htmlStr+="<td>"+age+"</td>"
                    htmlStr+="<td>"+renderTime(pisList[i].dateOfBirth).substring(0,10)+"</td>"
                    var phone = "";
                    if( pisList[i].phone != null ){
                        phone = pisList[i].phone;
                    }
                    htmlStr+="<td>"+phone+"</td>"
                    var number = "";
                    if( pisList[i].number != null ){
                        number = pisList[i].number;
                    }
                    htmlStr+="<td>"+number+"</td>"
                    htmlStr+="<td>"+renderTime(pisList[i].time)+"</td>"
                    htmlStr+="</tr>"
                }
                //展示到页面上
                $("#query_page").html(htmlStr);
                /*页面插件-分页展示*/
                //计算总页数
                var totalPages = 1;
                if (map.countList % pageSizeStr == 0) {
                    totalPages = map.countList / pageSizeStr;
                } else {
                    totalPages = parseInt(map.countList / pageSizeStr) + 1;
                }
                $("#query_page_less").bs_pagination({
                    currentPage: pageNoStr,	//当前页码
                    rowsPerPage: pageSizeStr,	//每页显示条数
                    totalRows: map.countList,	//总条数
                    totalPages: totalPages,//总页数
                    visiblePageLinks: 5,	//最多显示的卡片数
                    showGoToPage: true,		//是否显示跳转到几页
                    showRowsPerPage: true,	//是否显示每页显示条数
                    showRowsInfo: true,		//是否显示记录条数
                    //用来监听页号切换的事件，event代表事件，pageobj代表页面信息
                    onChangePage: function (event, pageObj) {
                        displayLess(pageObj.currentPage, pageObj.rowsPerPage);
                        pageObjIndexLess = pageObj.currentPage;
                    }
                });
            },
            error: function () {
                location.href = '404.jsp'
            }
        });
    }



    /**
     *转换日期格式问题
     * @param time
     * @returns {string}
     */
    function renderTime(date) {
        var dateee = new Date(date).toJSON();
        //return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
        return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
    }


})